package com.kaka.bus.engine.rechange;


import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.widget.ImageView;
import android.widget.TextView;

import com.kaka.bus.R;
import com.kaka.bus.base.BaseActivity;
import com.kaka.bus.bean.HttpWrapper;
import com.kaka.bus.constant.Constant;
import com.kaka.bus.util.U;

import butterknife.BindView;

public class GoRechangeActivity extends BaseActivity<GoRechangePresenter> implements GoRechangeContract.View {
    @BindView(R.id.toolbar_back)
    ImageView mToolbarBack;
    @BindView(R.id.toolbar_name)
    TextView mToolbarName;
    @BindView(R.id.tv_paystate)
    TextView tv_paystate;
    @BindView(R.id.btn_opinion)
    TextView btn_opinion;
    @BindView(R.id.tv_content)
    TextView tv_content;
    public static final String TYPE = "TYPE";
    public static final String PRODUCTID = "PRODUCTID";
    private int status;
    private int mProductId;

    @Override
    protected void initView() {
        super.initView();
        mToolbarName.setText("去支付");
        mToolbarBack.setOnClickListener(v -> finish());
        status = getIntent().getIntExtra(TYPE, 0);
        if (status == 2) {
            tv_content.setText("极速发卡时间:周一到周五9:00-18:00支付咨询服务费可享受极速发卡！");
            String paystate = "还差一步就可以发卡了，现在支付咨询服务费， 可优先获得发卡资质（此费用是支付给咔咔钱包的咨询服务费）。";
            tv_paystate.setText(U.toRichText(paystate, Color.parseColor("#ff8c6c"), paystate.indexOf("（"), paystate.indexOf("。") + 1));
        } else {
            tv_content.setText("极速放款时间:周一到周五9:00-18:00支付咨询服务费可享受极速放款！");
            String paystate = "还差一步就可以放款了，现在支付咨询服务费， 可优先获得放款资质（此费用是支付给咔咔钱包的咨询服务费）。";
            tv_paystate.setText(U.toRichText(paystate, Color.parseColor("#ff8c6c"), paystate.indexOf("（"), paystate.indexOf("。") + 1));
        }
        mProductId = getIntent().getIntExtra(PRODUCTID, -1);

        btn_opinion.setOnClickListener(view -> {
            mPresenter.getcheckPayFee(mProductId);
        });
    }

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_go_rechange;
    }

    @Override
    protected boolean needFullScreen() {
        return true;
    }

    @Override
    public void getcheckPayFeeSuccess(HttpWrapper<String> wrapper) {

        if (Constant.SUCCESS_CODE.equals(wrapper.getCode())) {
            Intent intent = new Intent(this, RechangeActivity.class);
            intent.putExtra(RechangeActivity.TYPE, status);
            startActivity(intent);
            finish();
        } else if ("202".equals(wrapper.getCode())) {
            new AlertDialog.Builder(this).setMessage(wrapper.getInfo()).setPositiveButton("确定", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).create().show();
        } else {
            showMessage(wrapper.getInfo());
        }

    }
}
